package net.tv90.bfmccore.command;

import net.tv90.bfmccore.helper.FactionHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class FactionCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 0) {
            sender.sendMessage("/fact setpla <玩家> 设置中国阵营");
            sender.sendMessage("/fact setrgf <玩家> 设置俄国阵营");
            sender.sendMessage("/fact setusmc <玩家> 设置美国阵营");
            sender.sendMessage("/fact setnone <玩家> 设置无阵营");
        }

        if(sender instanceof Player && !sender.isOp()) return false;

        else if(sender instanceof Player){
            switch (args[0].toLowerCase()) {
                case "setpla": {
                    FactionHelper.setCountry((Player) sender, FactionHelper.EnumCountry.CN);
                    break;
                }
                case "setrgf": {
                    FactionHelper.setCountry((Player) sender, FactionHelper.EnumCountry.RU);
                    break;
                }
                case "setusmc": {
                    FactionHelper.setCountry((Player) sender, FactionHelper.EnumCountry.US);
                    break;
                }
                case "setnone": {
                    FactionHelper.setCountry((Player) sender, FactionHelper.EnumCountry.NoFaction);
                    break;
                }
            }
        } else {
            if(args[1] == null || args[1].isEmpty()) throw new IllegalArgumentException("玩家名不能为空");
            Player p = sender.getServer().getPlayer(args[1]);
            switch (args[0].toLowerCase()) {
                case "setpla": {
                    FactionHelper.setCountry(p, FactionHelper.EnumCountry.CN);
                    break;
                }
                case "setrgf": {
                    FactionHelper.setCountry(p, FactionHelper.EnumCountry.RU);
                    break;
                }
                case "setusmc": {
                    FactionHelper.setCountry(p, FactionHelper.EnumCountry.US);
                    break;
                }
                case "setnone": {
                    FactionHelper.setCountry(p, FactionHelper.EnumCountry.NoFaction);
                    break;
                }
            }
        }


        return false;
    }

}
